
import {getBanners} from "@/api";
export default {
    namespaced:true,//命名空间，表示该模块数据仅能通 模块地址/数据来访问
    state:{
        loading:false,
        data:[]
    },
    mutations:{
        setLoading(state,payload){
            state.loading = payload;
        },
        setData(state,payload){
            state.data = payload;
        }
    },
    actions:{
        async fetchBanner(ctx){
            if(ctx.state.data.length){
                return;
            }
            ctx.commit('setLoading',true);
            const banners = await getBanners();
            ctx.commit('setData',banners);
            ctx.commit('setLoading',false);
        }
    }
}